package com.wetao.testkotlin

import java.io.File

object TestObject {
    //禁止有构造函数，单例
    val oInt = arrayListOf<String>()
    fun callFor() {
        for(o in oInt) {
            println(o)
        }
    }
}
object TestObject2 : Comparator<File> {
    override fun compare(o1: File, o2: File): Int {
        return o1.path.compareTo(o2.path, ignoreCase = true)
    }
}
data class TestObject3(val name:String){
    object TestObject4:Comparator<TestObject3>{
        override fun compare(o1: TestObject3, o2: TestObject3): Int {
            return o1.name.compareTo(o2.name)
        }
    }
}

class TestObject5{
    companion object{
        fun bar() {
            println("companion object 伴生对象")
        }
    }
}

class TestObject6 private constructor(val nickname:String) {
    companion object{
        fun newTestObject6(name:String) = TestObject6(name)
    }
}

class TestObject7(val nickname: String) {
    companion object TestObject8{
        fun call(name:String):TestObject7 = TestObject7(name)
    }
}

interface TestObject9{
    fun call(name:String):String
}
class TestObject10(){
    companion object : TestObject9 {
        override fun call(name: String): String {
            return name
        }
    }
}